package com.pets.controller;


import com.pets.pojo.EquipmentManagement;
import com.pets.pojo.FinancialManagement;
import com.pets.service.IFinancialManagementService;
import com.pets.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 * 财务管理 前端控制器
 * </p>
 *
 * @author 小陳同學
 * @since 2024-05-13
 */
@RestController
@RequestMapping("/financial-management")
@Api(tags = "财务管理")
public class FinancialManagementController {

    @Autowired
    private IFinancialManagementService financialManagementService;

    @ApiOperation("创建账单")
    @PostMapping
    public Result register(@RequestBody FinancialManagement financialManagement) {
        return financialManagementService.register(financialManagement);
    }

    @ApiOperation("根据id删除账单")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return financialManagementService.deleteById(id);
    }

    @ApiOperation("修改账单信息")
    @PutMapping("/update")
    public Result update(@RequestBody FinancialManagement financialManagement) {
        return financialManagementService.update(financialManagement);
    }


    @ApiOperation("查询账单分页集合")
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       @ApiParam(value = "账单名称")@RequestParam(required = false) String financialName) {
        return financialManagementService.selectPage(page, pageSize, financialName);
    }


    @ApiOperation("账单计图（只开给管理员）")
    @GetMapping("/orderStatistics")
    public Result orderStatistics(
            @ApiParam(value = "开始时间,格式: yyyy-MM-dd", required = true)
            @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
            @ApiParam(value = "结束时间,格式: yyyy-MM-dd", required = true)
            @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        return financialManagementService.orderStatistics(beginTime, endTime);
    }
}
